import Home from '../pages/Home';
import Cate from '../pages/Cate';
import Cart from '../pages/Cart';
import User from '../pages/User';
import Coupon from '../pages/Coupon';
import Reg from '../pages/Reg';
import Login from '../pages/Login';
import GoodsList from '../pages/GoodsList';
import Goods from '../pages/Goods';
import Error from '../pages/Error';


import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';
import Auth from '../components/Auth';
const routes = [
    {
        path: '/',
        // Component属性首字母必须大写, 属性值必须是一个组件对象(或者函数,不能是一个组件的调用标签)
        Component: () => {
            // 创建一个navigate对象
            const navigate = useNavigate();
            useEffect(() => {
                navigate('/home')
            });
        }
    },
    {
        path: '/home',
        // element属性值必须是一个组件的调用标签
        element: <Home />
    },
    {
        path: '/cate',
        element: <Cate />
    },
    {
        path: '/reg',
        element: <Reg />
    },
    {
        path: '/login',
        element: <Login />
    },
    {
        path: '/goodslist',
        element: <GoodsList />
    },
    {
        path: '/goods/:id',
        element: <Goods />
    },
    {
        path: '/user',
        element: <Auth><User /></Auth>
    },
    {
        path: '/cart',
        element: <Auth><Cart /></Auth>
    },
    {
        path: '/coupon',
        element: <Auth><Coupon /></Auth>
    },
    // 404路由
    {
        path: '*',
        element: <Error />
    },
];
export default routes;
